package com.shop.domain.user;

import java.math.BigDecimal;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.*;
import javax.persistence.Table;
import com.alibaba.fastjson.annotation.JSONField;
import com.shop.jpa.domain.BaseDomain;
import com.shop.jpa.support.JpaConst;
import com.shop.util.StrMaskUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import lombok.Data;

/**
 * <p>User 实体类</p>
 * <p>Table: t_user - 用户表</p>
 * @author generator
 * @date 2021-02-18 02:34:57
 */
@ApiModel("User 实体类")
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "t_user")
@SQLDelete(sql = "update t_user set is_deleted = 1 where id = ?")
@Where(clause = JpaConst.WHERE_CLAUSE_NOT_DELETED)
@DynamicInsert(true)
@DynamicUpdate(true)
public class User extends BaseDomain implements Serializable {

    @ApiModelProperty(value = "id", hidden = true)
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
	//@JSONField(serialize=false)
    private Long id;

    /**
	 * 用户账号
	 */
    @ApiModelProperty("用户账号")
	@Column(name = "account")
    private String account;

    /**
	 * 用户密码
	 */
    @ApiModelProperty("用户密码")
	@Column(name = "pwd")
    private String pwd;

    /**
	 * 真实姓名
	 */
    @ApiModelProperty("真实姓名")
	@Column(name = "real_name")
    private String realName;

    /**
	 * 身份证号码
	 */
    @ApiModelProperty("身份证号码")
	@Column(name = "card_id")
    @JSONField(serialize = false)
    private String cardId;

    /**
	 * 用户备注
	 */
    @ApiModelProperty("用户备注")
	@Column(name = "mark")
    private String mark;

    /**
	 * 用户昵称
	 */
    @ApiModelProperty("用户昵称")
	@Column(name = "nickname")
    private String nickname;

    /**
	 * 用户头像
	 */
    @ApiModelProperty("用户头像")
	@Column(name = "avatar")
    private String avatar;

    /**
	 * 手机号码
	 */
    @ApiModelProperty("手机号码")
	@Column(name = "mobile")
    private String mobile;

    /**
	 * 添加ip
	 */
    @ApiModelProperty("添加ip")
	@Column(name = "add_ip")
    private String addIp;

    /**
	 * 最后一次登录时间
	 */
    @ApiModelProperty("最后一次登录时间")
	@Column(name = "last_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date lastTime;

    /**
	 * 最后一次登录ip
	 */
    @ApiModelProperty("最后一次登录ip")
	@Column(name = "last_ip")
    private String lastIp;

    /**
	 * 用户余额
	 */
    @ApiModelProperty("用户余额")
	@Column(name = "balance")
    private BigDecimal balance;

    /**
	 * TG
	 */
    @ApiModelProperty("TG")
	@Column(name = "coin")
    private BigDecimal coin;

    /**
     * 积分
     */
    @ApiModelProperty("积分")
    @Column(name = "integral")
    private BigDecimal integral;

    /**
	 * 佣金金额
	 */
    @ApiModelProperty("佣金积分")
	@Column(name = "brokerage")
    private BigDecimal brokerage;

    /**
	 * 1为正常，0为禁止
	 */
    @ApiModelProperty("1为正常，0为禁止")
	@Column(name = "status")
    private Integer status;

    /**
	 * 等级id
	 */
    @ApiModelProperty("等级id")
	@Column(name = "level")
    private Long level;

    /**
	 * 推广人id
	 */
    @ApiModelProperty("推广人id")
	@Column(name = "spread_uid")
    private Long spreadUid;

    /**
	 * 推广人关联时间
	 */
    @ApiModelProperty("推广人关联时间")
	@Column(name = "spread_time")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date spreadTime;

    /**
	 * 关系字符串
	 */
    @ApiModelProperty("关系字符串")
	@Column(name = "spreadids")
    private String spreadids;

    /**
	 * 当前用户所属总裁ID
	 */
    @ApiModelProperty("当前用户所属总裁ID")
	@Column(name = "ceo_id")
    private Long ceoId;

    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty("创建时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    /**
     * 最后一次更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty("最后一次更新时间")
    @JSONField(serialize=false)
    private Date updateTime;




    /**
     * 是否删除 0：不删除   1：删除
     */
    @Column(name = "is_deleted")
    @ApiModelProperty("是否删除 0：不删除   1：删除")
    @JSONField(serialize=false)
    private Integer isDeleted;

    /**
     * 脱敏手机号
     */
    @Transient
    @ApiModelProperty("脱敏手机号")
    private String maskMobile;
    public String getMaskMobile() {
        if(StringUtils.isNotBlank(this.maskMobile)){
            return this.maskMobile;
        }
        return StrMaskUtil.maskMobile(this.mobile);
    }

    /**
     * 脱敏姓名
     */
    @Transient
    @ApiModelProperty("脱敏姓名")
    private String maskRealName;
    public String getMaskRealName() {
        if(StringUtils.isNotBlank(this.maskRealName)){
            return this.maskRealName;
        }
        return StrMaskUtil.maskRealityName(this.realName);
    }

    /**
     * 脱敏身份证号
     */
    @Transient
    @ApiModelProperty("脱敏身份证号")
    private String maskCardId;
    public String getMaskCardId() {
        if(StringUtils.isNotBlank(this.maskCardId)){
            return this.maskCardId;
        }
        return StrMaskUtil.maskIdNumber(this.cardId);
    }
}